home *** CD-ROM | disk | FTP | other *** search
/ Atari Forever 4 / Atari Forever 4.zip / Atari Forever 4.iso / PD_THEMA / EDITOREN / 7UP_PD / PICKLST2.C < prev    next >
C/C++ Source or Header  |  1998-03-14  |  14KB  |  584 lines

  1. /* Liste der zuletzt editierten Dateien (soll angeblich nicht funktionieren) */
  2. /*****************************************************************************
  3. *
  4. *                                              7UP
  5. *                                      Modul: PICKLIST.C
  6. *                                     (c) by TheoSoft '93
  7. *
  8. *****************************************************************************/
  9. #include <portab.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <ctype.h>
  14. #include <aes.h>
  15. #include <vdi.h>
  16. #include <ext.h>
  17.  
  18. #include "alert.h"
  19.  
  20. #include "forms.h"
  21. #include "windows.h"
  22. #include "7up.h"
  23. #include "version.h"
  24.  
  25. #include "language.h"
  26.  
  27. #define MAXENTRIES     8L
  28. #define MAXLETTERS    42L
  29. #define MAXSPACES     42L
  30. #define MAXPICKFILES 128L
  31. #define notnull(a) (((a)>0)?(a):(1))
  32. #define FLAGS15 0x8000
  33.  
  34. extern int boxh;
  35.  
  36. typedef struct
  37. {
  38.     char name[PATH_MAX];
  39.     char line[8];
  40.     char info[41];
  41. }PICKLISTE;
  42.  
  43. long *get_cookie(long cookie);
  44. void objc_update(OBJECT *tree, int obj, int depth);
  45. void set_vslider(OBJECT *tree, int ext, int slide,  int newpos);
  46. static int _hndl_picklist(OBJECT *tree, char *filename, long *line);
  47. char *find_7upinf(char *path, char *ext, int mode);
  48. long strcchg(register char *str, register char old, register char new);
  49. void hsort(char *base, int num, int size, int (*cmp)());
  50. char *stristr(char *s1, char *s2);
  51. int list_do(OBJECT *tree, int exit_obj, long *first, int *which, int count, int *done);
  52. WINDOW *Wreadtempfile(char *filename, int mode);
  53. int access(char *filename, int fattr);
  54.  
  55. static PICKLISTE *pl=NULL;
  56.  
  57. void free_picklist()
  58. {
  59.     if(pl)
  60.         free(pl);
  61.     pl=NULL;
  62.     return;
  63. }
  64.  
  65. int load_picklist()
  66. {
  67.     FILE *fp;
  68.     char filename[PATH_MAX];
  69.     long i,size,lines;
  70.     int count=0;
  71.  
  72.     if((fp=fopen(find_7upinf(filename,"PCK",FALSE),"r"))!=NULL)
  73.     {                                                            /* Pickfile öffnen */
  74.         graf_mouse(BUSY_BEE,NULL);    
  75.         if((pl=malloc(MAXPICKFILES*sizeof(PICKLISTE)))!=NULL)
  76.         {
  77.             memset(pl,0,MAXPICKFILES*sizeof(PICKLISTE));
  78.             fgets(filename,VERSIONSTRLEN+1,fp);
  79.             filename[strlen(filename)-1]=0; /*CR weg*/
  80.             if(!strcmp(filename,VERSIONNAME))
  81.             {
  82.                 while(!feof(fp))
  83.                 {
  84.                     fgets(pl[count].name,PATH_MAX,fp);
  85.                     pl[count].name[strlen(pl[count].name)-1]=0; /*CR weg*/
  86.                     if(*pl[count].name)
  87.                     {
  88.                         fgets(pl[count].line,PATH_MAX,fp);
  89.                         pl[count].line[strlen(pl[count].line)-1]=0; /*CR weg*/
  90.                         fgets(pl[count].info,41,      fp);
  91.                         pl[count].info[strlen(pl[count].info)-1]=0; /*CR weg*/
  92.                         count++;
  93.                     }
  94.                 }
  95.             }
  96.             else
  97.             {
  98.                 if(filelength(fileno(fp)) > 0)
  99.                     form_alert(1,Apicklist[2]);
  100.             }
  101.         }
  102.         fclose(fp);
  103.         graf_mouse(ARROW,NULL);    
  104.     }
  105.     return(count);
  106. }
  107.  
  108. int change_picklist(int count)
  109. {
  110.     FILE *fp;
  111.     char filename[PATH_MAX];
  112.     int i;
  113.  
  114.     if((fp=fopen(find_7upinf(filename,"PCK",TRUE),"w"))!=NULL)
  115.     {                                                    /* Pickfile öffnen */
  116.         graf_mouse(BUSY_BEE,NULL);    
  117.         fprintf(fp,"%s\n",VERSIONNAME);
  118.         for(i=0; i<count; i++)
  119.             if(*pl[i].name)
  120.             {
  121.                 fprintf(fp,"%s\n",pl[i].name);
  122.                 fprintf(fp,"%s\n",pl[i].line);
  123.                 fprintf(fp,"%s\n",pl[i].info);
  124.             }
  125.         fclose(fp);                                                /* Datei schließen */
  126.         graf_mouse(ARROW,NULL);    
  127.     }
  128. }
  129.  
  130. static int name_existiert(char *name) /* abklappern, ob Fenstername schon vorhanden */
  131. {
  132.     int i;
  133.     extern WINDOW _wind[];
  134.     for(i=1; i<MAXWINDOWS; i++) /* Fensternamen sichern */
  135.     {
  136.         if((_wind[i].w_state & CREATED) && /* Fenster muß existieren */
  137.             !strcmp(name,(char *)Wname(&_wind[i])))
  138.             return(TRUE);
  139.     }
  140.     return(FALSE);
  141. }
  142.  
  143. static char *getinfo(char *pathname, int count)
  144. {
  145.     int i;
  146.     
  147.     for(i=0; i<count; i++)
  148.         if(!stricmp(pl[i].name, pathname))
  149.             return(pl[i].info);
  150.     return("");
  151. }
  152.  
  153. void append_picklist(OBJECT * tree, char *pathname, long line)
  154. {
  155.     FILE *fp;
  156.     char filename[PATH_MAX];
  157.     int i, count=0;
  158.     char info[41]="";
  159.     
  160.     extern WINDOW _wind[];
  161.     
  162.     if(Wcount(CREATED)==0)
  163.         return;
  164.  
  165.     if(!(tree[PICKAKTIV].ob_state & SELECTED)) /* ist ausgeschaltet 8.1.95 */
  166.         return;
  167.  
  168.     count=load_picklist();
  169.     if((fp=fopen(find_7upinf(filename,"PCK",TRUE),"w"))!=NULL)
  170.     {
  171.         graf_mouse(BUSY_BEE,NULL);    
  172.         if(pathname)
  173.         {
  174.             fprintf(fp,"%s\n",VERSIONNAME);
  175.             for(i=0; i<count; i++)
  176.                if(stricmp(pathname, pl[i].name))
  177.                {                            /* alles sichern, was anders ist */
  178.                     fprintf(fp,"%s\n",pl[i].name);
  179.                     fprintf(fp,"%s\n",pl[i].line);
  180.                     fprintf(fp,"%s\n",pl[i].info);
  181.                 }
  182.                 else
  183.                     strcpy(info,pl[i].info);
  184.             fprintf(fp,"%s\n",pathname);
  185.             fprintf(fp,"%ld\n",line);
  186.             fprintf(fp,"%s\n",info);
  187.         }
  188.         else
  189.         {
  190.             fprintf(fp,"%s\n",VERSIONNAME);
  191.             for(i=0; i<count; i++)
  192.                 if(!name_existiert(pl[i].name))
  193.                 {                            /* alles sichern, was anders ist */
  194.                     fprintf(fp,"%s\n",pl[i].name);
  195.                     fprintf(fp,"%s\n",pl[i].line);
  196.                     fprintf(fp,"%s\n",pl[i].info);
  197.                 }
  198.             for(i=1; i<MAXWINDOWS; i++)
  199.                 if((_wind[i].w_state & CREATED) &&
  200.                     (strcmp(NAMENLOS,(char *)Wname(&_wind[i]))) &&
  201.                     (1/*!stristr(pickbuff,(char *)Wname(&_wind[i]))*/))
  202.                 {
  203.                     fprintf(fp,"%s\n",(char *)Wname(&_wind[i]));
  204.                     fprintf(fp,"%ld\n",_wind[i].row + _wind[i].hfirst/_wind[i].hscroll + 1);
  205.                     fprintf(fp,"%s\n",getinfo((char *)Wname(&_wind[i]),count));
  206.                 }
  207.         }
  208.         fclose(fp);
  209.         graf_mouse(ARROW,NULL);    
  210.     }
  211.     free_picklist();
  212. }
  213.  
  214. static char *stradj(char *dest, char *src, int maxlen)
  215. {
  216.     register int len;
  217.     dest[0]=' ';
  218.     if((len=strlen(src))>maxlen)
  219.     {
  220.         strncpy(&dest[1],src,maxlen/2);
  221.         strncpy(&dest[maxlen/2+1],&src[len-maxlen/2],maxlen/2);
  222.         dest[maxlen/2-1+1]='.';
  223.         dest[maxlen/2+0+1]='.';
  224.         dest[maxlen/2+1+1]='.';
  225.     }
  226.     else
  227.     {
  228.         strcpy(&dest[1],src);
  229.         memset(&dest[len+1],' ',maxlen-len+1);
  230.     }
  231.     dest[maxlen+1]=' ';
  232.     dest[maxlen+2]=0;
  233.     return(dest);
  234. }
  235.  
  236. static int list_do(OBJECT *tree, int exit_obj, long *first, int *which, int count, int *done)
  237. {
  238.     int my,ret,newpos,oby,kstate;
  239. /*    
  240.     *which=-1;
  241. */
  242.     graf_mkstate(&ret,&my,&ret,&kstate);
  243.     switch(exit_obj)
  244.     {
  245.         case PICKUP:
  246.             if(kstate & (K_LSHIFT|K_RSHIFT))
  247.             {
  248.                 if((*first-MAXENTRIES)>0)
  249.                     *first-=MAXENTRIES;
  250.                 else
  251.                     *first=0;
  252.             }
  253.             else
  254.             {
  255.                 if(*first>0)
  256.                     (*first)--;
  257.                 else
  258.                     exit_obj=-1;
  259.             }
  260.             break;
  261.         case PICKDN:
  262.             if(kstate & (K_LSHIFT|K_RSHIFT))
  263.             {
  264.                 if((*first+MAXENTRIES)<(count-MAXENTRIES))
  265.                     *first+=MAXENTRIES;
  266.                 else
  267.                     *first=count-MAXENTRIES;
  268.             }
  269.             else
  270.             {
  271.                 if(*first<count-MAXENTRIES)
  272.                     (*first)++;
  273.                 else
  274.                     exit_obj=-1;
  275.             }
  276.             break;
  277.         case PICKSLID:
  278.             graf_mouse(FLAT_HAND,NULL);
  279.             newpos=graf_slidebox(tree,PICKBOX,PICKSLID,1);
  280.             graf_mouse(ARROW,NULL);
  281.             *first=((newpos*(count-MAXENTRIES))/1000L);
  282.             break;
  283.         case PICKBOX:
  284.             objc_offset(tree,exit_obj+1,&ret,&oby);
  285.             if(my>oby)
  286.             {
  287.                 if((*first+MAXENTRIES)<(count-MAXENTRIES))
  288.                     *first+=MAXENTRIES;
  289.                 else
  290.                     *first=count-MAXENTRIES;
  291.             }
  292.             else
  293.             {
  294.                 if((*first-MAXENTRIES)>0)
  295.                     *first-=MAXENTRIES;
  296.                 else
  297.                     *first=0;
  298.             }
  299.             break;
  300.         case PICKFIRST:
  301.         case PICKFIRST+1:
  302.         case PICKFIRST+2:
  303.         case PICKFIRST+3:
  304.         case PICKFIRST+4:
  305.         case PICKFIRST+5:
  306.         case PICKFIRST+6:
  307.         case PICKLAST:
  308.             *which=exit_obj-PICKFIRST+*first;
  309.             break;
  310.     }
  311.     if((exit_obj) & 0x8000) /* Verlassen mit Doppelklick */
  312.     {
  313.         switch((exit_obj) &= 0x7FFF)
  314.         {
  315.             case PICKUP:
  316.                 if(*first>0)
  317.                     *first=0;
  318.                 else
  319.                     exit_obj=-1;
  320.                 break;
  321.             case PICKDN:
  322.                 if(*first<count-MAXENTRIES)
  323.                     *first=count-MAXENTRIES;
  324.                 else
  325.                     exit_obj=-1;
  326.                 break;
  327.             case PICKFIRST:
  328.             case PICKFIRST+1:
  329.             case PICKFIRST+2:
  330.             case PICKFIRST+3:
  331.             case PICKFIRST+4:
  332.             case PICKFIRST+5:
  333.             case PICKFIRST+6:
  334.             case PICKLAST:
  335.                 *which=exit_obj-PICKFIRST+*first;
  336.                 *done=TRUE;
  337.                 break;
  338.         }
  339.     }
  340.     return(exit_obj);
  341. }
  342.  
  343. static int _hndl_picklist(OBJECT *tree, char *filename, long *line)
  344. {
  345.     static long first2=0;
  346.  
  347.     long first,newpos;
  348.     int which=-1,count,count2,exit_obj,done=FALSE,changed=FALSE;
  349.     int i,k,ret,kstate;
  350.     struct ffblk fileRec;
  351.     
  352.     char string[41];
  353.  
  354.     count=load_picklist();
  355.     if(count==0)
  356.         return(-1);
  357.     count2=count;
  358. /*    
  359.     hsort(pl,count,sizeof(char *),strcmp);
  360. */
  361. /**************************************************************************/
  362. /* letzte OK-Werte einstellen, falls verstellt und Abbruch gedrückt wurde */
  363. /**************************************************************************/
  364.     first=first2;
  365.  
  366.     for(i=PICKFIRST; i<=PICKLAST; i++)
  367.     {
  368.         tree[i].ob_state&=~SELECTED;
  369.         tree[i].ob_flags&=~SELECTABLE;
  370.     }
  371.     tree[PICKSLID].ob_height=
  372.              max(boxh,MAXENTRIES*tree[PICKBOX].ob_height/max(MAXENTRIES,count));
  373.     newpos=/*(int)*/((first*1000L)/notnull(count-MAXENTRIES));
  374.    newpos=max(0,newpos);
  375.     newpos=min(newpos,1000);
  376.     set_vslider(tree,PICKBOX,PICKSLID,newpos);
  377.  
  378.     for(i=first,k=0; i<count && k<MAXENTRIES; i++,k++)
  379.     {
  380.         stradj(string,pl[i].name,MAXLETTERS-2);
  381.         form_write(tree,PICKFIRST+k,string,FALSE);
  382.         tree[PICKFIRST+k].ob_flags|=SELECTABLE;
  383.     }
  384. /*MT 16.7.94*/
  385.     form_write(tree,PICKCOMMENT,"",FALSE);
  386.  
  387.     memset(string,' ',MAXLETTERS);
  388.     string[MAXLETTERS]=0;
  389.     for(; k<MAXENTRIES; k++)
  390.         form_write(tree,PICKFIRST+k,string,FALSE);
  391. /*
  392.     if(get_cookie('MiNT') && (_GemParBlk.global[1] != 1)) /* MultiTOS */
  393.         tree[PICKBOX].ob_spec.obspec.fillpattern=4;
  394. */
  395.     tree[PICKDEL].ob_state|=DISABLED;
  396.     tree[PICKCLEAN].ob_state|=DISABLED;
  397.  
  398.     sprintf(string,PICKFILES,count2);
  399.     form_write(tree,PICKINFO,string,FALSE);
  400. /*   
  401.     if(_GemParBlk.global[0] >=0x0340) /* Ab Falcon Muster ändern */
  402.     {
  403.         tree[PICKBOX ].ob_spec.obspec.fillpattern=4;
  404.     }
  405. */
  406.     form_exopen(tree,0);
  407.     do
  408.     {
  409.         exit_obj=form_exdo(tree,0);
  410.  
  411.         if(which>-1)
  412.             form_read(tree,PICKCOMMENT,pl[which].info);
  413.  
  414.         exit_obj=list_do(tree, exit_obj, &first, &which, count, &done);
  415.         switch(exit_obj)
  416.         {
  417.             case PICKHELP:
  418.                 form_alert(1,Apicklist[0]);
  419.                 objc_change(tree,exit_obj,0,tree->ob_x,tree->ob_y,tree->ob_width,tree->ob_height,tree[exit_obj].ob_state&~SELECTED,TRUE);
  420.                 break;
  421.             case PICKDEL:
  422.                 if(which>-1)
  423.                 {
  424.                     graf_mouse(BUSY_BEE,NULL);    
  425.                    if(tree[PICKCLEAN].ob_state & SELECTED)
  426.                    {
  427.                       for(i=0; i<count; i++)
  428.                       {
  429. /* Löschen, wenn A | B | N | (U & (A | B)) | 'nicht existent' */
  430.                          if((toupper(pl[i].name[0]) == 'A') ||
  431.                             (toupper(pl[i].name[0]) == 'B') ||
  432.                             (toupper(pl[i].name[0]) == 'N') ||
  433.                             ((toupper(pl[i].name[0]) == 'U') && 
  434.                              ((toupper(pl[i].name[3]) == 'A') ||
  435.                               (toupper(pl[i].name[3]) == 'B'))) ||
  436.                             (!access(pl[i].name,0)) )
  437.                             {
  438.                                     *pl[i].name=0; /* Löschen */
  439.                                     if((i+PICKFIRST-first)>=PICKFIRST && 
  440.                                        (i+PICKFIRST-first)<=PICKLAST)
  441.                                     {
  442.                                         tree[i+PICKFIRST-first].ob_state&=~SELECTED;
  443.                                         memset(string,' ',MAXLETTERS);
  444.                                         string[MAXLETTERS]=0;
  445.                                         form_write(tree,i+PICKFIRST-first,string,TRUE);
  446.                                     }
  447.                             }
  448.                       }
  449.                    }
  450.                    else
  451.                     {
  452.                         *pl[which].name=0; /* Löschen */
  453.                         tree[which+PICKFIRST-first].ob_state&=~SELECTED;
  454.                         memset(string,' ',MAXLETTERS);
  455.                         string[MAXLETTERS]=0;
  456.                         form_write(tree,which+PICKFIRST-first,string,TRUE);
  457.                     }
  458.                     change_picklist(count);
  459.                     which=-1;
  460.                     changed=TRUE;
  461.                    sprintf(string,PICKFILES,--count2);    
  462.                    form_write(tree,PICKINFO,string,TRUE);
  463.                     graf_mouse(ARROW,NULL);    
  464.                 }
  465.                 objc_change(tree,exit_obj,0,tree->ob_x,tree->ob_y,
  466.                                 tree->ob_width,tree->ob_height,tree[exit_obj].ob_state&~SELECTED,TRUE);
  467.                 tree[PICKCLEAN].ob_state&=~SELECTED;
  468.                 tree[PICKCLEAN].ob_state|=DISABLED;
  469.                 objc_update(tree,PICKCLEAN,0);
  470.                 tree[PICKDEL].ob_state|=DISABLED;
  471.                 objc_update(tree,PICKDEL,0);
  472.                 break;
  473.             case PICKFIRST:
  474.             case PICKFIRST+1:
  475.             case PICKFIRST+2:
  476.             case PICKFIRST+3:
  477.             case PICKFIRST+4:
  478.             case PICKFIRST+5:
  479.             case PICKFIRST+6:
  480.             case PICKLAST:
  481.                sprintf(string,PICKFILESSELECTED,count2);    
  482.                form_write(tree,PICKINFO,string,TRUE);
  483. /*MT 16.7.94*/
  484.                 if(which>-1)
  485.                     form_write(tree,PICKCOMMENT,pl[which].info,TRUE);
  486.                 objc_change(tree,PICKCLEAN,0,tree->ob_x,tree->ob_y,
  487.                                 tree->ob_width,tree->ob_height,tree[PICKCLEAN].ob_state&~DISABLED,TRUE);
  488.                 objc_change(tree,PICKDEL,0,tree->ob_x,tree->ob_y,
  489.                                 tree->ob_width,tree->ob_height,tree[PICKDEL].ob_state&~DISABLED,TRUE);
  490.                 changed=TRUE;
  491.                 break;
  492.             case PICKUP:
  493.             case PICKDN:
  494.             case PICKBOX:
  495.             case PICKSLID:
  496.                 if(count>MAXENTRIES)
  497.                 {
  498.                     for(i=PICKFIRST; i<=PICKLAST; i++)
  499.                         if(tree[i].ob_state & SELECTED)
  500.                             which=i-PICKFIRST+first;
  501.                     newpos=/*(int)*/((first*1000L)/notnull(count-MAXENTRIES));
  502.                     newpos=min(max(0,newpos),1000);
  503.                     set_vslider(tree,PICKBOX,PICKSLID,newpos);
  504.                     objc_update(tree,PICKBOX,MAX_DEPTH);
  505.                     for(i=first,k=0; k<MAXENTRIES; i++,k++)
  506.                     {
  507.                         stradj(string,pl[i].name,MAXLETTERS-2);
  508.                         form_write(tree,PICKFIRST+k,string,TRUE);
  509.                     }
  510.                     if(which>-1)
  511.                         form_write(tree,PICKCOMMENT,pl[which].info,TRUE);
  512.                 }
  513.                 break;
  514.             case PICKOK:
  515.             case PICKABBR:
  516.                 done=TRUE;
  517.                 break;
  518.         }
  519.     }
  520.     while(!done);
  521.     form_exclose(tree, exit_obj, 0);
  522.     tree[PICKOK].ob_state&=~SELECTED;
  523.     if(which>-1)
  524.     {
  525.         strcpy(filename,pl[which].name);
  526.         *line = atol(pl[which].line);
  527.     }
  528.     if(changed)/*nach Löschen auf null, damit Neuaufbau klappt*/
  529.         first=0;
  530. /*
  531.     if(changed && (exit_obj==PICKOK))
  532.     {
  533.         if(which>-1)
  534.             form_read(tree,PICKCOMMENT,pl[which].info);
  535.         change_picklist(count);
  536.         first=0;
  537.     }
  538. */
  539.     free_picklist();
  540.     first2=first;
  541.     switch(exit_obj)
  542.     {
  543.         case PICKFIRST:
  544.         case PICKFIRST+1:
  545.         case PICKFIRST+2:
  546.         case PICKFIRST+3:
  547.         case PICKFIRST+4:
  548.         case PICKFIRST+5:
  549.         case PICKFIRST+6:
  550.         case PICKLAST:
  551.         case PICKOK:
  552.             if(which>-1)
  553.             {
  554.                 return(TRUE);
  555.             }
  556.             break;
  557.     }
  558.     return(FALSE);
  559. }
  560.  
  561. int hndl_picklist(OBJECT *tree)
  562. {
  563.     char filename[PATH_MAX];
  564.     long line=0;
  565.     WINDOW *wp;
  566.     int a;
  567.     a = tree[PICKAKTIV].ob_state;
  568.     
  569.     switch(_hndl_picklist(tree,filename,&line))
  570.     {
  571.         case TRUE:
  572.             if((wp=Wreadtempfile(filename,FALSE))!=NULL)
  573.                 if(line > 1) /* nur wenn positioniert werden soll */
  574.                     hndl_goto(wp, NULL, line);
  575.             break;
  576.         case -1:
  577.             form_alert(1,Apicklist[1]);
  578.             /* durchfallen!!! */
  579.         case FALSE:
  580.             tree[PICKAKTIV].ob_state = a;
  581.             break;
  582.     }
  583. }
  584.